//
//  BuySiteTicketRequest.m
//  EasyToo
//
//  Created by zhengzhe on 13-8-25.
//
//

#import "BuySiteTicketRequest.h"

@implementation BuySiteTicketRequest

- (id)buySiteTicket:(id<ServerCommunicationDelegate>)delegate
        reserveName:(NSString*)reserveName
        reserveDate:(NSString*)reserveDate
      reserveNumber:(NSString*)reserveNumber
        mobilephone:(NSString*)mobilephone
      sceneTicketId:(NSString*)sceneTicketId
         mobileType:(NSString*)mobileType
            webTime:(NSString*)webTime
           allPrice:(int)allPrice;
{
    self = [super init];
    if (self) {
        self.delegate = delegate;
        
        self.requestName = @"BuySiteTicketRequest";

        self.url = PROTOCOL_ORDER_URL;
        
        [self.bodyJsonDict setObject:[self URLEncodedString:reserveName] forKey:@"reserveName"];
        [self.bodyJsonDict setObject:reserveDate forKey:@"reserveDate"];
        [self.bodyJsonDict setObject:reserveNumber forKey:@"reserveNumber"];
        [self.bodyJsonDict setObject:mobilephone forKey:@"mobilephone"];
        [self.bodyJsonDict setObject:sceneTicketId forKey:@"sceneTicketId"];
        [self.bodyJsonDict setObject:mobileType forKey:@"mobileType"];
        [self.bodyJsonDict setObject:webTime forKey:@"webTime"];
        
        [self.headerJsonDict setObject:@"013006" forKey:@"TranCode"];
        
        //银联支付价格
        [self.headerJsonDict setObject:[NSString stringWithFormat:@"%d", allPrice] forKey:@"TxAmt"];
        
        [self buildJsonRequest];
    }
    return self;
}

- (NSString*)URLEncodedString:(NSString*)input
{
    NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                                           (CFStringRef)input,
                                                                           NULL,
                                                                           CFSTR("!*'();:@&=+$,/?%#[]"),
                                                                           kCFStringEncodingUTF8);
    [result autorelease];
    return result;
}

@end
